<template>
	<view class="content-box">
		<view class="top">
			<view class="left_box">
				<image src="../../static/images/icon/fh.png" style="width: 40rpx;margin-top: 25rpx;" mode="widthFix"
					@click="back"></image>
			</view>
			<view class="left_title">
				答题卡
			</view>
		</view>
		<view class="mt150"></view>
		<view class="dtk_item">
			<view class="title">
				一、选择题（共{{questspra.danXuan.length}}道）
			</view>
			<view class="b1" v-for="(item,index) in questspra.danXuan" :key="index" @click="getItem(item)">
				<view v-if="item.isAnswer=='y'" class="se">{{index+1}}</view>
				<view v-else class="def">{{index+1}}</view>
			</view>
			<view class="title">
				二、多选题（共{{questspra.duoXuan.length}}道）
			</view>
			<view class="b1" v-for="(item,index) in questspra.duoXuan" :key="index" @click="getItem(item)">
				<view v-if="item.isAnswer=='y'" class="se">{{index+1}}</view>
				<view v-else class="def">{{index+1}}</view>
			</view>
			<view class="title">
				三、判断题（共{{questspra.panDuan.length}}道）
			</view>
			<view class="b1" v-for="(item,index) in questspra.panDuan" :key="index" @click="getItem(item)">
				<view v-if="item.isAnswer=='y'" class="se">{{index+1}}</view>
				<view v-else class="def">{{index+1}}</view>
			</view>
			<view class="title">
				四、填空题（共{{questspra.tianKong.length}}道）
			</view>
			<view class="b1" v-for="(item,index) in questspra.tianKong" :key="index" @click="getItem(item)">
				<view v-if="item.isAnswer=='y'" class="se">{{index+1}}</view>
				<view v-else class="def">{{index+1}}</view>
			</view>
			<view class="title">
				五、简答题（共{{questspra.jianDa.length}}道）
			</view>
			<view class="b1" v-for="(item,index) in questspra.jianDa" :key="index">
				<view v-if="item.isAnswer=='y'" class="se">{{index+1}}</view>
				<view v-else class="def">{{index+1}}</view>
			</view>
			<view class="b1" v-for="(item,index) in questspra.jianDa" :key="index">
				<view v-if="item.isAnswer=='y'" class="se">{{index+1}}</view>
				<view v-else class="def">{{index+1}}</view>
			</view>
			<view class="dkt_msg">
				<view class="msg">
					<view class="msg1">

					</view>
					<view class="msg2">
						未答
					</view>
					<view class="msg3">

					</view>
					<view class="msg2">
						已答
					</view>
				</view>
			</view>
			<view class="left_30"></view>
		</view> 
		<view class="bottom">
			<view class="time1">
				<view class="b1">
					<image src="../../static/training/up.png" class="b2" mode="widthFix" @click="back"></image>
				</view>
				<view class="b3" @click="back">
					返回答题区
				</view>
			</view>
			<!-- <view class="time1">
				<view class="b1">
					<image src="../../static/training/dtk.png" class="b2" mode="widthFix"></image>
				</view>
				<view class="b3">
					查看末做题
				</view>
			</view> -->
		</view>

	</view>
</template>

<script>
	import {
		submitPracticePaper
	} from "@/common/api/training/training.js";
	export default {
		data() {
			return {
				questspra: {
					danXuan: [],
					duoXuan: [],
					panDuan: [],
					tianKong: [],
					jianDa: []
				},
				questList: {}
			};
		},
		onLoad() {
			//从缓存中取出题目
			const questspra_lx = uni.getStorageSync("questspra_lx");
			const timelong=uni.getStorageSync('timelong');
			console.log("timelong",timelong)
			questspra_lx.timelong=timelong;
			//分题型
			const danXuan = []; //单选题
			const duoXuan = []; //多选题
			const panDuan = []; //判断题
			const tianKong = []; //天空题
			const jianDa = []; //简答题
			for (var i = 0; i < questspra_lx.questspra.length; i++) {
				let obj = questspra_lx.questspra[i];
				if (obj.qtype == 1) {
					danXuan.push(obj);
				} else if (obj.qtype == 2) {
					duoXuan.push(obj);
				} else if (obj.qtype == 3) {
					panDuan.push(obj);
				} else if (obj.qtype == 4) {
					tianKong.push(obj);
				} else {
					jianDa.push(obj)
				}
			}
			this.questspra.danXuan = danXuan;
			this.questspra.duoXuan = duoXuan;
			this.questspra.panDuan = panDuan;
			this.questspra.tianKong = tianKong;
			this.questspra.jianDa = jianDa;

			questspra_lx.quests = questspra_lx.questspra;
			questspra_lx.questspra = null;
			this.questList = questspra_lx;
			console.log(this.questList)

		},
		methods: {
			back() {
				uni.navigateBack()
			},
			info() {
				uni.navigateTo({
					url: "/pages/training/info"
				})
			},
			getItem(item) {
				let index = 0;
				for (var i = 0; i < this.questList.quests.length; i++) {
					var obj = this.questList.quests[i];
					if (item.id == obj.id) {
						index = i;
					}
				}
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				prevPage.indexQ(index);
				uni.navigateBack()
			},
			submitP() {
				var this_=this;
				uni.showModal({
					title: '提醒',
					content: '确定提交？',
					success(res) {
						if (res.confirm) { 
							submitPracticePaper(this_.questList).then((res) => {
								if (res && res.code == 200 && res.data) {
									uni.showModal({
										title:'提示',
										content:'提交成功',
										showCancel:false,
										success(r) {
											uni.switchTab({
												url: '/pages/index/index'
											});
										}
									}) 
								}
							});
						}
					}
				})
			}
		},
	};
</script>

<style lang="scss" scoped>
	@import url("../../common/base.css");
	@import url("./topic.scss");
</style>